import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
import babel from 'rollup-plugin-babel';
import eslint from 'rollup-plugin-eslint';
import replace from 'rollup-plugin-replace';
import postcss from 'rollup-plugin-postcss';


import simplevars from 'postcss-simple-vars';
import nested from 'postcss-nested';
import cssnext from 'postcss-cssnext';
import cssnano from 'cssnano';

const production = !process.env.ROLLUP_WATCH;

export default {
    input: 'src/js/main.js',
    output: {
        file: 'build/bundle.js',
        format: 'iife',
        name: 'MyBundle'
    },
    plugins: [
        postcss({
            plugins: [
                simplevars(),
                nested(),
                cssnext({ warnForDuplicates: false, }),
                cssnano(),
            ],
            extensions: ['.css']
        }),
        json(),  
        resolve(), // tells Rollup how to find modules in node_modules
        commonjs(), // converts modules to ES modules
        eslint({
            exclude: [
                'src/styles/**'
            ]
        }),
        babel({
            exclude: "node_modules/**"
        }),
        replace({
            exclude: "node_modules/**",
            ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
        }),
        production && uglify() // minify, but only in production
    ],
    sourceMap: true

};